home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Doors_System / XPR / Main.C < prev    next >
C/C++ Source or Header  |  1996-11-06  |  40KB  |  1,628 lines

  1. /*
  2.  
  3.    XPR door
  4.    ========
  5.  
  6.    This door provides access to the XPR Libraries for HBBS so that you can up
  7.    and download files.
  8.  
  9.    the TRANSFER door will call this most of the time.  It takes the following options
  10.  
  11.    N_ND->ActiveDoor->SystemOptions
  12.    ===============================
  13.  
  14.    None.
  15.  
  16.    dooroptions
  17.    ===========
  18.  
  19.    <xpr<lib>.library>
  20.  
  21.    TAGS [NOWAREZ] [NOSYSTEM]
  22.  
  23.    W=<upload path>         filenames are added to this if open() fails..
  24.                            note: *** MUST *** be specified BEFORE any U=<file> parameter!
  25.  
  26.    D=<download path>       you should normally only specify one place and that should
  27.                              be HBBS:Nodes/NodeX/Playpen/ (or wherever the node's playpen is..)
  28.  
  29.                             IMPORTANT:  must have trailing / or :
  30.                             --> not any more! 9/jul/1996
  31.  
  32.    U=<file to upload>      you can specify more than one of these only if the protocol
  33.                              is a batch upload protocol
  34.                              e.g.
  35.                              U=dh2:warez/miggy/hotsoft.lha
  36.                              U=dh2:warez/miggy/newsoft.lha
  37.                              ....
  38.  
  39.    S                       tells xpr to skip files that are present in the current
  40.                            conference's download directories.
  41.  
  42.    C                       tells xpr to remove users credits for transferred files
  43.  
  44.    O=<xprlibrary options>  some options for the xpr library..
  45.  
  46.    E.G.  (examples are for node 3)
  47.  
  48.      to download users tagged files and remove creds
  49.  
  50.        XPR 3 xprzmodem.library TAGS C
  51.  
  52.      get some files into the node's playpen.
  53.  
  54.        XPR 3 xprzmodem.library S D=HBBS:Nodes/Node3/PlayPen/
  55.  
  56.  
  57.    todo
  58.    ====
  59.  
  60.    move files if they are fucked as soon as they are fclose'd
  61.    also need to call background filechecker here too..
  62.  
  63.    implement L=<text file with list of files to upload>
  64.  
  65.  
  66.    notes
  67.    =====
  68.  
  69.    You've no idea how much hassle this door was to write..! :-)
  70.  
  71.  
  72. */
  73.  
  74. #include <exec/types.h>
  75. #include <exec/memory.h>
  76. #include <dos/dos.h>
  77. #include <clib/exec_protos.h>
  78. #include <clib/dos_protos.h>
  79. #include <clib/alib_protos.h>
  80.  
  81. #include <stdlib.h>
  82. #include <string.h>
  83. #include <stdio.h>
  84. #include <ctype.h>
  85. #include <time.h>
  86.  
  87. #include <devices/serial.h>
  88. #include <devices/timer.h>
  89.  
  90. #include <dos/dosextens.h>
  91. #include <intuition/screens.h>
  92. #include <intuition/intuition.h>
  93. #include <intuition/gadgetclass.h>
  94. #include <libraries/gadtools.h>
  95. #include <diskfont/diskfont.h>
  96. #include <utility/utility.h>
  97. #include <graphics/gfxbase.h>
  98. #include <workbench/workbench.h>
  99. #include <graphics/scale.h>
  100. #include <clib/wb_protos.h>
  101. #include <clib/intuition_protos.h>
  102. #include <clib/gadtools_protos.h>
  103. #include <clib/graphics_protos.h>
  104. #include <clib/utility_protos.h>
  105. #include <clib/diskfont_protos.h>
  106.  
  107. #include "xpr_gui.h"
  108.  
  109. #ifdef __SASC
  110. int CXBRK(void) { return(0); }
  111. int _CXBRK(void) { return(0); }
  112. void chkabort(void) {}
  113. #endif
  114.  
  115. #include <HBBS/ANSI_Codes.h>
  116. #include <HBBS/Defines.h>
  117. #include <HBBS/types.h>
  118. #include <HBBS/structures.h>
  119. #include <HBBS/hbbscommon_protos.h>
  120. #include <HBBS/hbbscommon_pragmas.h>
  121. #include <HBBS/Hbbsnode_protos.h>
  122. #include <HBBS/Hbbsnode_pragmas.h>
  123. #include <HBBS/release.h>
  124. char *versionstr="$VER: XPR "RELEASE_STR;
  125.  
  126. struct Library *HBBSCommonBase=NULL;
  127. struct Library *HBBSNodeBase=NULL;
  128. struct TextFont *HBBSFont=NULL;
  129. struct BBSGlobalData *BBSGlobal=NULL;
  130. struct NodeData *N_ND=NULL;
  131. int N_NodeNum=-1;
  132. char outstr[1024];
  133. long __near __stack=16384;
  134.  
  135. struct FileBuffer
  136. {
  137.   struct Node node; // filename in ln_Name
  138.   BPTR FH;
  139.   ULONG BytesTransferred;
  140.   ULONG BlocksTransferred;
  141.   ULONG ActualSize;
  142.   BOOL Testing;
  143.   BOOL ReadFile;
  144.  
  145. };
  146.  
  147. #include "xproto.h"  // XPR protocol stuff...
  148.  
  149.  
  150. UBYTE ZModemCancel[] =
  151. {
  152.   24,24,24,24,24,24,24,24,24,24,
  153.    8, 8, 8, 8, 8, 8, 8, 8, 8, 8
  154. };
  155.  
  156. // *** Flags
  157.  
  158. BOOL TWindowOpen=FALSE;
  159. BOOL CheckConfPaths=FALSE;
  160.   // if set then xpr_fopen() has to check all the Conf->Download paths for an existing file
  161.   // and skip it if the file already exists.
  162. BOOL TakeCreds=FALSE;
  163. BOOL xprseropen;
  164. // *** File Info
  165.  
  166. struct List *UL_FileList=NULL; // a list of FileBuffer nodes..
  167. LONG UL_Files=0;
  168.  
  169. struct List *DL_FileList=NULL; // a list of FileBuffer nodes..
  170. LONG DL_Files=0;
  171.  
  172. UBYTE *DL_Path=NULL;
  173. BOOL DL_PathOK=FALSE;
  174.  
  175. UBYTE *UL_Path=NULL;
  176. BOOL UL_PathOK=FALSE;
  177.  
  178. struct FileBuffer *CurrentFile=NULL;
  179. LONG CurrentFileNum=1;
  180.  
  181. #define T_SEND 1
  182. #define T_RECEIVE 2
  183.  
  184. ULONG TransferType=0;
  185.  
  186. // ** Stuff for the XPR bit..
  187.  
  188. UBYTE *xprlibname=NULL;
  189. UBYTE *xprlibopts=NULL;
  190.  
  191. struct Library *XProtocolBase;
  192. struct XPR_IO *xio;
  193.  
  194. struct timerequest *treq;
  195. struct MsgPort *tport;
  196. char timeropen;
  197.  
  198. struct IOExtSer theserio;
  199.  
  200. struct IOExtSer *xpr_serio;
  201. struct MsgPort *NewPort,*OldPort;
  202.  
  203. // ************* Misc Functions ***************
  204.  
  205. VOID cleanup(ULONG num)
  206. {
  207.   if (HBBSNodeBase)
  208.   {
  209.     HBBS_CleanUpDoor();
  210.     CloseLibrary (HBBSNodeBase);
  211.   }
  212.  
  213.   if (HBBSCommonBase)
  214.   {
  215.     HBBS_CleanUpCommon();
  216.     CloseLibrary (HBBSCommonBase);
  217.   }
  218.  
  219.   if (num) printf("Door Error = %d\n",num);
  220.  
  221.   exit(0);
  222. }
  223.  
  224. static VOID init(char *name)
  225. {
  226.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  227.   {
  228.     cleanup(1);
  229.   }
  230.  
  231.   if (!(HBBS_InitCommon()))
  232.   {
  233.     cleanup(2);
  234.   }
  235.  
  236.   if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  237.   {
  238.     cleanup(3);
  239.   }
  240.  
  241.   if (!(HBBS_InitDoor(N_NodeNum,name)))
  242.   {
  243.     cleanup(4);
  244.   }
  245.   SetProgramName(name);
  246. }
  247.  
  248.  
  249. // ************* Main Door Functions ***************
  250.  
  251. // Timer Routines..
  252.  
  253. long opentimer(void)
  254. {
  255.   if (!(treq=AllocVec(sizeof(struct timerequest),MEMF_CLEAR|MEMF_PUBLIC)))
  256.   {
  257.     return(-1);
  258.   }
  259.   if(!(tport=CreateMsgPort()))
  260.   {
  261.     FreeVec(treq);
  262.     return(-1);
  263.   }
  264.   treq->tr_node.io_Message.mn_ReplyPort=tport;
  265.   if (OpenDevice("timer.device",UNIT_VBLANK,(struct IORequest*)treq,0))
  266.   {
  267.     DeleteMsgPort(tport);
  268.     FreeVec(treq);
  269.     return(-1);
  270.   }
  271.   timeropen=1;
  272.   return(0);
  273. }
  274.  
  275. static void closetimer(void)
  276. {
  277.   if(treq)
  278.   {
  279.     if(timeropen) CloseDevice((struct IORequest*)treq);
  280.     if(tport) DeleteMsgPort(tport);
  281.     FreeVec(treq);
  282.   }
  283. }
  284.  
  285. void qtimer(ULONG micros)
  286. {
  287. /*
  288.   long secs=0;
  289.   if (micros > 1000000)
  290.   {
  291.     secs = micros / 1000000;
  292.     micros = micros % 1000000;
  293.   }
  294.   treq->tr_time.tv_micro=micros;
  295.   treq->tr_time.tv_secs=secs;
  296. */
  297.  
  298.   treq->tr_time.tv_micro=micros % 1000000;
  299.   treq->tr_time.tv_secs=micros / 1000000;
  300.  
  301.   treq->tr_node.io_Command=TR_ADDREQUEST;
  302.   SetSignal(0,1L<<tport->mp_SigBit);
  303.   SendIO((struct IORequest*)treq);
  304. }
  305.  
  306. BOOL GrabSerial( void )
  307. {
  308.   AbortSerRead(); // just in case there are any pending serial requests..
  309.   xprseropen=FALSE;
  310.   xpr_serio=NULL;
  311.   if(!(NewPort=CreatePort(0,0)))
  312.     return(FALSE);
  313.  
  314.   if (xpr_serio=(struct IOExtSer *) CreateExtIO(NewPort,(ULONG)sizeof(struct IOExtSer)))
  315.   {
  316.     if (N_ND->NodeDevice.NullModemCable)
  317.     {
  318.       xpr_serio->io_SerFlags       = SERF_SHARED;
  319.     }
  320.     else
  321.     {
  322.       xpr_serio->io_SerFlags       = SERF_SHARED|SERF_7WIRE|SERF_XDISABLED|SERF_RAD_BOOGIE;
  323.     }
  324.     if (!(OpenDevice((STRPTR)N_ND->NodeDevice.SerialDevice,(ULONG)N_ND->NodeDevice.SerialUnit,(struct IORequest *)xpr_serio,0L) ))
  325.     {
  326.       xprseropen=TRUE;
  327.       xpr_serio->IOSer.io_Command  = CMD_RESET;
  328.       DoIO((struct IORequest *)xpr_serio);
  329.  
  330.  
  331.       // setup port with correct baud rate etc..
  332.       xpr_serio->IOSer.io_Command  = SDCMD_SETPARAMS;
  333.       xpr_serio->io_SerFlags       |= SERF_XDISABLED;
  334.       xpr_serio->io_Baud           = N_ND->NodeDevice.SerialBaud;
  335.       DoIO((struct IORequest *)xpr_serio);
  336.  
  337.       SetSignal(0,1L<<OldPort->mp_SigBit);
  338.  
  339.       return(TRUE);
  340.     }
  341.   }
  342.   return(FALSE);
  343. }
  344.  
  345. void ReleaseSerial( void )
  346. {
  347.   if (xprseropen)
  348.   {
  349.     CloseDevice((struct IORequest*)xpr_serio);
  350.   }
  351.  
  352.   if (xpr_serio) DeleteExtIO((struct IORequest*)xpr_serio);
  353.  
  354.   if (NewPort) DeletePort(NewPort);
  355. }
  356.  
  357.  
  358.  
  359. // ************* XPR Functions ***************
  360.  
  361.  
  362. LONG __saveds __asm xpr_finfo(register __a0 STRPTR FileName,register __d0 LONG InfoType)
  363. {
  364.   struct FileInfoBlock FB;
  365.   BPTR FL;
  366.   LONG result=0;
  367.  
  368. #ifdef debugmode
  369.   printf("xpr_finfo, FileName = \"%s\" type = %ld\n",FileName,InfoType);
  370. #endif
  371.  
  372.   switch (InfoType)
  373.   {
  374.     case 1:
  375.  
  376.       if (TransferType==T_RECEIVE && DL_PathOK)
  377.       {
  378.         strcpy(outstr,DL_Path);
  379.         strcat(outstr,FileName);
  380.       }
  381.       else
  382.       {
  383.         strcpy(outstr,FileName);
  384.       }
  385.  
  386.       if(FL=Lock(outstr,SHARED_LOCK))
  387.       {
  388.         if (Examine(FL,&FB))
  389.         {
  390.           result=FB.fib_Size;
  391.         }
  392.         UnLock(FL);
  393.       }
  394.       else
  395.       {
  396.         DOOR_SysopText("Lock Failed!\r\n");
  397.       }
  398.       break;
  399.  
  400.     case 2:
  401.       result = 1; // always a binary transfer
  402.       break;
  403.   }
  404. #ifdef debugmode
  405.   printf("xpr_finfo, returning = %ld\n",result);
  406. #endif
  407.   return((LONG)result);
  408. }
  409.  
  410. LONG __saveds __asm xpr_ffirst(register __a0 STRPTR Buffer,register __a1 STRPTR Pattern)
  411. {
  412.  
  413.   #ifdef debugmode
  414.   printf("xpr_ffirst, pattern = \"%s\"\n",Pattern);
  415.   #endif
  416.  
  417.   if (UL_Files)
  418.   {
  419.     CurrentFile=(struct FileBuffer*)UL_FileList->lh_Head;
  420.     CurrentFileNum=1;
  421.     strcpy(Buffer,CurrentFile->node.ln_Name);
  422.   }
  423.  
  424.   #ifdef debugmode
  425.   printf("xpr_ffirst, buffer now = \"%s\"\n",Buffer);
  426.   #endif
  427.   return(1);
  428. }
  429.  
  430. LONG __saveds __asm xpr_fnext(register __d0 LONG OldState,register __a0 STRPTR Buffer,register __a1 STRPTR Pattern)
  431. {
  432.   #ifdef debugmode
  433.   printf("xpr_fnext, OldState = %ld, pattern = \"%s\"\n",OldState,Pattern);
  434.   #endif
  435.  
  436.   if (CurrentFileNum<UL_Files)
  437.   {
  438.     CurrentFile=(struct FileBuffer*)CurrentFile->node.ln_Succ;
  439.     CurrentFileNum++;
  440.     strcpy(Buffer,CurrentFile->node.ln_Name);
  441.     #ifdef debugmode
  442.     printf("xpr_fnext, filename: %s, returning 1",Buffer);
  443.     #endif
  444.     return((LONG)1);
  445.   }
  446.   #ifdef debugmode
  447.   printf("No more files for xpr_fnext\n");
  448.   #endif
  449.   return((LONG)0);
  450. }
  451.  
  452. LONG __saveds __asm xpr_gets(register __a0 STRPTR Prompt,register __a1 STRPTR Buffer)
  453. {
  454.   #ifdef debugmode
  455.   printf("xpr_gets, Prompt = \"%s\", Buffer = \"%s\"\n",Prompt,Buffer);
  456.   #endif
  457.   return((LONG)0);
  458. }
  459.  
  460. LONG __saveds __asm xpr_fopen(register __a0 STRPTR FileName,register __a1 STRPTR AccessMode)
  461. {
  462.   BPTR FL;
  463.   BOOL FileExists=FALSE;
  464.   UBYTE tmpfilename[1024],newname[1024];
  465.   struct ConfData *Conf=NULL;
  466.   struct Node *node;
  467.   struct NodeData *nd;
  468.  
  469.   #ifdef debugmode
  470.   sprintf(outstr,"xpr_open, file = \"%s\", mode = \"%s\"\r\n",FileName,AccessMode);
  471.   DOOR_SysopText(outstr);
  472.   #endif
  473.  
  474.   if (stricmp(AccessMode,"r")==0)
  475.   {
  476.     if (TransferType==T_RECEIVE)
  477.     {
  478.       // *C* check here for existance of file in the PartUploads dir and move it to the
  479.       // playpen.. Also check in the current conference's dl_paths (if in a conf..)
  480.  
  481.       if ((CheckConfPaths) && (Conf=FindConf()))
  482.       {
  483.         for (node=Conf->Download->lh_Head;!FileExists && node->ln_Succ;node=node->ln_Succ)
  484.         {
  485.           strcpy(tmpfilename,node->ln_Name);
  486.           strcat(tmpfilename,FileName);
  487.           if (PathOK(tmpfilename)) FileExists=TRUE;
  488.         }
  489.  
  490.         if (!FileExists) // now check in the other nodes playpen dirs to see if
  491.         {                // someone else is uploading the same file..
  492.           for (nd=(struct NodeData *)BBSGlobal->NodeList->lh_Head;!FileExists && nd->node.ln_Succ;nd=(struct NodeData*)nd->node.ln_Succ)
  493.           {
  494.             strcpy(tmpfilename,nd->NodeSettings.NodePlayPen);
  495.             AddPart(tmpfilename,FileName,1024);
  496.             if (PathOK(tmpfilename)) FileExists=TRUE;
  497.           }
  498.         }
  499.  
  500.         if (!FileExists)
  501.         {
  502.           // check in partupload directory and if present copy to playpen so user can
  503.           // resume the u/l..
  504.  
  505.           for (node=Conf->PartUpload->lh_Head;!FileExists && node->ln_Succ;node=node->ln_Succ)
  506.           {
  507.             sprintf(tmpfilename,"%s%s@%ld",node->ln_Name,FileName,N_ND->User.CallData.UserID);
  508.             if (PathOK(tmpfilename))
  509.             {
  510.               strcpy(newname,DL_Path);
  511.               AddPart(newname,FileName,1024);
  512.               Rename(tmpfilename,newname);    // *C* change and add a copy here if rename fails!!
  513.               FileExists=TRUE;
  514.             }
  515.           }
  516.           FileExists=FALSE; // as we don't want to skip anymore..
  517.         }
  518.  
  519.       }
  520.  
  521.       if ((FileExists) || (!DL_PathOK))
  522.       {
  523.         // file exists, no path specified
  524.         #ifdef debugmode
  525.         puts("file exists or no dlpath");
  526.         #endif
  527.         return(0); // this will cause the file to be SKIPPED
  528.       }
  529.  
  530.       CurrentFile=NULL;
  531.  
  532.       strcpy(tmpfilename,DL_Path);
  533.       AddPart(tmpfilename,FileName,1024);
  534.  
  535.       if (CurrentFile=(struct FileBuffer*)HBBS_CreateNode(tmpfilename,sizeof(struct FileBuffer)))
  536.       {
  537.         CurrentFile->Testing=TRUE;
  538.       }
  539.     }
  540.  
  541.     if (TransferType==T_SEND)
  542.     {
  543.       if (stricmp(FileName,CurrentFile->node.ln_Name)!=0)
  544.       {
  545.         printf("Where the fuck did this filename come from ??\n: %s\n",FileName);
  546.         return(0);
  547.       }
  548.     }
  549.   }
  550.   else // transfer is a download (i.e. user sending the BBS a file.
  551.   {
  552.     // transfer is a download, so add the path of the download directory
  553.     // to the FileName
  554.  
  555.     strcpy(tmpfilename,DL_Path);
  556.     strcat(tmpfilename,FileName);
  557.  
  558.     if (CurrentFile=(struct FileBuffer*)HBBS_CreateNode(tmpfilename,sizeof(struct FileBuffer)))
  559.     {
  560.       AddTail(DL_FileList,(struct Node*)CurrentFile);
  561.       DL_Files++;
  562.     }
  563.   }
  564.  
  565.   if (!CurrentFile) // *R* needed ?
  566.   {
  567.     return(0);
  568.   }
  569.  
  570.   switch(AccessMode[0])
  571.   {
  572.     case 'r':
  573.       // open the file, if it fails and we're sending a file then add the u/l path to the filename
  574.       CurrentFile->FH=Open(CurrentFile->node.ln_Name,AccessMode[1]=='+' ? MODE_READWRITE : MODE_OLDFILE);
  575.  
  576. /* not used here... see at param checking part of program!
  577.       if (!(CurrentFile->FH=Open(CurrentFile->node.ln_Name,AccessMode[1]=='+' ? MODE_READWRITE : MODE_OLDFILE)))
  578.       {
  579.         if (UL_PathOK && TransferType==T_SEND)
  580.         {
  581.           FreeStr(CurrentFile->node.ln_Name);
  582.           strcpy(tmpfilename,UL_Path);
  583.           AddPart(tmpfilename,FileName,1023);
  584.           if (CurrentFile->node.ln_Name=DupStr(tmpfilename))
  585.           {
  586.             CurrentFile->FH=Open(CurrentFile->node.ln_Name,AccessMode[1]=='+' ? MODE_READWRITE : MODE_OLDFILE);
  587.           }
  588.         }
  589.       }
  590. */
  591.       break;
  592.     case 'w':
  593.       // open file for writing, truncate old file if it exists
  594.       if (AccessMode[1]=='+')  // truncate file (well, delete it anyway)
  595.       {
  596.         if (FL = Lock(CurrentFile->node.ln_Name,ACCESS_WRITE))
  597.         {
  598.           UnLock(FL);
  599.           DeleteFile(CurrentFile->node.ln_Name);
  600.         }
  601.         CurrentFile->FH=Open(CurrentFile->node.ln_Name,MODE_READWRITE);
  602.       }
  603.       else
  604.       {
  605.         CurrentFile->FH=Open(CurrentFile->node.ln_Name,MODE_NEWFILE);
  606.       }
  607.       break;
  608.     case 'a':
  609.       // open file, seek to end, create new file if none exists.
  610.  
  611.       if (FL=Lock(CurrentFile->node.ln_Name,ACCESS_WRITE))
  612.       {
  613.         UnLock(FL);
  614.         if(CurrentFile->FH=Open(CurrentFile->node.ln_Name,MODE_READWRITE))
  615.         {
  616.           DOOR_SysopText("seeking..");
  617.           if (Seek(CurrentFile->FH,0,OFFSET_END) == -1) // error seeking ?
  618.           {
  619.             Close(CurrentFile->FH);
  620.             CurrentFile->FH = NULL;
  621.           } else DOOR_SysopText("ok!\r\n");
  622.         }
  623.       }
  624.       else
  625.       {
  626.         CurrentFile->FH=Open(CurrentFile->node.ln_Name,MODE_NEWFILE);
  627.       }
  628.       break;
  629.   }
  630.  
  631.   if (CurrentFile->FH==NULL) // open failed!
  632.   {
  633.     if (CurrentFile->Testing)
  634.     {
  635.       HBBS_FreeNode((struct Node*)CurrentFile,FALSE);
  636.     }
  637.     return(NULL);
  638.   }
  639.  
  640.   #ifdef debugmode
  641.   printf("xpr_fopen, returning %x\r\n",(LONG)CurrentFile);
  642.   #endif
  643.  
  644.  
  645.   return((LONG)CurrentFile);
  646. }
  647.  
  648. LONG __saveds __asm xpr_fclose(register __a0 struct FileBuffer *FileBuf)
  649. {
  650. #ifdef debugmode
  651.   printf("xpr_fclose, FileBuf->Filename = \"%s\" FileBuf->FH = %x\n",FileBuf->node.ln_Name,FileBuf->FH);
  652. #endif
  653.   if ((FileBuf) && (FileBuf->FH))
  654.   {
  655.     Close(FileBuf->FH);
  656.     if (FileBuf->Testing)
  657.     {
  658.       HBBS_FreeNode((struct Node*)FileBuf,FALSE);
  659.     }
  660.   }
  661.   return((LONG)0);
  662. }
  663.  
  664. LONG __saveds __asm xpr_fread(register __a0 APTR Buffer,register __d0 LONG Size,register __d1 long Count,register __a1 struct FileBuffer *FileBuf)
  665. {
  666.   LONG retval;
  667. #ifdef debugmode
  668.   printf("xpr_fread, Size = %ld, Count = %ld\n",Size,Count);
  669. #endif
  670.   // check params are ok..
  671.   if (!Size)
  672.   {
  673. #ifdef debugmode
  674.     puts("xpr_fread size = 0!");
  675. #endif
  676.     return(0);
  677.   }
  678. //  if (Buffer == NULL || FileBuf==NULL || FileBuf->FH==NULL || Size==0 || Count==0) return((LONG)0);
  679.   retval=Read(FileBuf->FH,Buffer,Size*Count);
  680. #ifdef debugmode
  681.   printf("xpr_fread returning %ld\n",retval);
  682. #endif
  683.  
  684.   if (retval) FileBuf->ReadFile=TRUE; // so we can determine if a file was skipped if it was
  685.                                       // already present on the user's machine (not the sysop's)
  686.  
  687.   return(retval);
  688. }
  689.  
  690. LONG __saveds __asm xpr_fwrite(register __a0 APTR Buffer,register __d0 LONG Size,register __d1 LONG Count,register __a1 struct FileBuffer *FileBuf)
  691. {
  692.   LONG retval;
  693. #ifdef debugmode
  694.   printf("xpr_write, Size = %ld, Count = %ld\n",Size,Count);
  695. #endif
  696.  
  697. //  return(Size * Count);
  698.  
  699.   // check params are ok..
  700. //  if (Buffer == NULL || FileBuf==NULL || FileBuf->FH==NULL || Size==0 || Count==0) return((LONG)0);
  701.   if (!Size)
  702.   {
  703. #ifdef debugmode
  704.     puts("xpr_fwrite size = 0!");
  705. #endif
  706.     return(0);
  707.   }
  708.   retval=Write(FileBuf->FH,Buffer,Size*Count);
  709. #ifdef debugmode
  710.   printf("xpr_write returning %ld\n",retval);
  711. #endif
  712.   return(retval);
  713. }
  714.  
  715. LONG __saveds __asm xpr_fseek(register __a0 struct FileBuffer *FileBuf,register __d0 LONG Offset,register __d1 LONG Origin)
  716. {
  717.   LONG Mode=-1;
  718.   LONG tmpval;
  719.  
  720. #ifdef debugmode
  721.   printf("xpr_seek, Offset = %ld, Origin = %ld\n",Offset,Origin);
  722. #endif
  723.  
  724.   // check params are ok..
  725.   if (FileBuf==NULL || FileBuf->FH==NULL) return((LONG)-1);
  726.  
  727.   switch(Origin)
  728.   {
  729.     case 0: Mode=OFFSET_BEGINNING; break;
  730.     case 1: Mode=OFFSET_CURRENT; break;
  731.     case 2: Mode=OFFSET_END; break;
  732.     default: return((LONG)-1);
  733.   }
  734.   tmpval=Seek(FileBuf->FH,Offset,Mode);
  735. #ifdef debugmode
  736.   printf("xpr_seek, seek() result = %ld\r\n",tmpval);
  737. #endif
  738.   return((tmpval==-1) ? (LONG)-1 : (LONG)0);
  739.  
  740. }
  741.  
  742. LONG __saveds __asm xpr_unlink(register __a0 STRPTR FileName)
  743. {
  744. #ifdef debugmode
  745.   printf("xpr_unlick, FileName = \"%s\"\n",FileName);
  746. #endif
  747.   return(DeleteFile(FileName));
  748. }
  749.  
  750. void xpr_closedisplay(void)
  751. {
  752. #ifdef debugmode
  753.   printf("xpr_closedisplay\n");
  754. #endif
  755.   return;
  756. }
  757.  
  758. LONG __saveds __asm xpr_displayupdate(register __a0 struct XPR_UPDATE *xu)
  759. {
  760.   long ud=xu->xpru_updatemask;
  761.   LONG tempnum;
  762.  
  763.   if(ud&XPRU_BYTES)
  764.   {
  765.     if (CurrentFile)
  766.     {
  767.       CurrentFile->BytesTransferred=xu->xpru_bytes;
  768.  
  769.       if (TWindowOpen)
  770.       {
  771.         GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Transferred],XPRWin,NULL,GTNM_Number,(LONG)xu->xpru_bytes,TAG_DONE);
  772.  
  773.         if (CurrentFile->ActualSize) tempnum=(LONG)((CurrentFile->BytesTransferred * 100) / CurrentFile->ActualSize); else tempnum=0;
  774.         GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Percent],XPRWin,NULL,GTNM_Number,(LONG)tempnum,TAG_DONE);
  775.  
  776.         tempnum=CurrentFile->ActualSize - CurrentFile->BytesTransferred;
  777.         GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Remaining],XPRWin,NULL,GTNM_Number,(LONG)tempnum,TAG_DONE);
  778.       }
  779.     }
  780.  
  781.   }
  782.  
  783.   if(ud&XPRU_PROTOCOL)
  784.   {
  785.     if (TWindowOpen)
  786.     {
  787.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Library],XPRWin,NULL,GTTX_Text,xu->xpru_protocol,TAG_DONE);
  788.     }
  789.   }
  790.   if(ud&XPRU_FILENAME)
  791.   {
  792.     if (TWindowOpen)
  793.     {
  794.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_File],XPRWin,NULL,GTTX_Text,xu->xpru_filename,TAG_DONE);
  795.     }
  796.   }
  797.   if(ud&XPRU_FILESIZE)
  798.   {
  799.     if (TWindowOpen)
  800.     {
  801.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Size],XPRWin,NULL,GTNM_Number,(LONG)xu->xpru_filesize,TAG_DONE);
  802.     }
  803.  
  804.     if (CurrentFile)
  805.     {
  806.       CurrentFile->ActualSize=xu->xpru_filesize;
  807.     }
  808.   }
  809.   if(ud&XPRU_MSG)
  810.   {
  811.     if (TWindowOpen)
  812.     {
  813.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Message],XPRWin,NULL,GTTX_Text,xu->xpru_msg,TAG_DONE);
  814.     }
  815.  
  816.   }
  817.   if(ud&XPRU_BLOCKS)
  818.   {
  819.     if (CurrentFile)
  820.     {
  821.       CurrentFile->BlocksTransferred=xu->xpru_blocks;
  822.     }
  823.     if (TWindowOpen)
  824.     {
  825.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Blocks],XPRWin,NULL,GTNM_Number,(LONG)xu->xpru_blocks,TAG_DONE);
  826.     }
  827.   }
  828.   if(ud&XPRU_ERRORMSG)
  829.   {
  830.     if (TWindowOpen)
  831.     {
  832.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Message],XPRWin,NULL,GTTX_Text,xu->xpru_errormsg,TAG_DONE);
  833.     }
  834.   }
  835.  
  836.   if(ud&XPRU_DATARATE)
  837.   {
  838.     if (TWindowOpen)
  839.     {
  840.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_CPS],XPRWin,NULL,GTNM_Number,(LONG)xu->xpru_datarate,TAG_DONE);
  841.     }
  842.   }
  843.   if(ud&XPRU_BLOCKSIZE)
  844.   {
  845.     if (TWindowOpen)
  846.     {
  847.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_BlockSize],XPRWin,NULL,GTNM_Number,(LONG)xu->xpru_blocksize,TAG_DONE);
  848.     }
  849.   }
  850.   if(ud&XPRU_ERRORS)
  851.   {
  852.     if (TWindowOpen)
  853.     {
  854.       GT_SetGadgetAttrs(XPRWinGadgets[XPRWin_Errors],XPRWin,NULL,GTNM_Number,(LONG)xu->xpru_errors,TAG_DONE);
  855.     }
  856.   }
  857.  
  858.   /*
  859.   if(ud&XPRU_ELAPSEDTIME)printf("%d Elapsed Time\n",xu->xpru_elapsedtime);
  860.   if(ud&XPRU_EXPECTTIME) printf("%d ExpectTime\n",xu->xpru_expecttime);
  861.   if(ud&XPRU_BLOCKCHECK) printf("%d Block Check\n",xu->xpru_blockcheck);
  862.   */
  863.  
  864.   return(0);
  865. }
  866.  
  867. LONG __saveds __asm xpr_swrite(register __a0 APTR Buffer,register __d0 LONG Size)
  868. {
  869. #ifdef debugmode
  870.   printf("xpr_swrite, Size = %ld\n",Size);
  871. #endif
  872.   if (Size==0)
  873.   {
  874. #ifdef debugmode
  875.     puts("xpr_swrite invalid size!");
  876. #endif
  877.     return((LONG)0);
  878.   }
  879.  
  880.   xpr_serio->IOSer.io_Length=Size;
  881.   xpr_serio->IOSer.io_Data=Buffer;
  882.   xpr_serio->IOSer.io_Command=CMD_WRITE;
  883.   SetSignal(0,1L<<NewPort->mp_SigBit);
  884.   DoIO((struct IORequest *)xpr_serio);
  885. #ifdef debugmode
  886.   printf("xpr_swrite returning %ld\n",xpr_serio->IOSer.io_Error);
  887. #endif
  888.   return((LONG)xpr_serio->IOSer.io_Error);
  889. }
  890.  
  891.  
  892. LONG __saveds __asm xpr_chk4abort(void)
  893. {
  894.   struct IntuiMessage *im=0;
  895.   LONG retval=0;
  896.  
  897.   if(TWindowOpen)
  898.   {
  899.     if (im=(struct IntuiMessage *)GetMsg(XPRWin->UserPort))
  900.     {
  901.       // We've only got one type of message, so it must be the close gadget
  902.       // being pressed!
  903.  
  904.       ReplyMsg((struct Message *)im);
  905.       retval=-1;
  906.  
  907.     }
  908.   }
  909.  
  910.   if (CarrierLost()) retval=-1;
  911.  
  912. #ifdef debugmode
  913.   printf("xpr_chkabort returning %ld\n",retval);
  914. #endif
  915.   return(retval);
  916. }
  917.  
  918.  
  919. LONG __saveds __asm xpr_sread(register __a0 APTR Buffer,register __d0 LONG Size,register __d1 ULONG Timeout)
  920. {
  921.   ULONG WaitSigs,ReturnedSigs;
  922.  
  923.   LONG BytesWaiting,AmountToRead;
  924.  
  925.  
  926. #ifdef debugmode
  927.   printf("xpr_sread, Size = %ld, Timeout = %ld\n",Size,Timeout);
  928. #endif
  929.  
  930.   if (Size==0)
  931.   {
  932. #ifdef debugmode
  933.     puts("xpr_sread invalid size");
  934. #endif
  935.     return((LONG)0);
  936.   }
  937.  
  938.   if (CarrierLost()) return((LONG)-1);
  939.  
  940.   /* See how many bytes there are */
  941.  
  942.   xpr_serio->IOSer.io_Command=SDCMD_QUERY;
  943.   DoIO((struct IORequest *)xpr_serio);
  944.   BytesWaiting=xpr_serio->IOSer.io_Actual;
  945.  
  946. #ifdef debugmode
  947.   printf("%d Bytes Waiting\n",BytesWaiting);
  948. #endif
  949.  
  950.   if(!Timeout || BytesWaiting >= Size)
  951.   {
  952.     if(!BytesWaiting)
  953.     {
  954.       // no data to be read..
  955.       return(0);
  956.     }
  957.     else
  958.     {
  959.       // some data is waiting
  960.       if(BytesWaiting>Size) AmountToRead=Size;
  961.       xpr_serio->IOSer.io_Command=CMD_READ;
  962.       xpr_serio->IOSer.io_Data=Buffer;
  963.       xpr_serio->IOSer.io_Length=AmountToRead;
  964.       DoIO((struct IORequest *)xpr_serio);
  965.  
  966.       // return amount of bytes read
  967. #ifdef debugmode
  968.       printf("xpr_sread, returning %ld\n",AmountToRead);
  969. #endif
  970.       return((LONG)AmountToRead);
  971.     }
  972.   }
  973.  
  974.   xpr_serio->IOSer.io_Command=CMD_READ;
  975.   xpr_serio->IOSer.io_Data=Buffer;
  976.   xpr_serio->IOSer.io_Length=Size;
  977.  
  978.   SetSignal(0,1L<<NewPort->mp_SigBit);
  979.   SendIO((struct IORequest *)xpr_serio);
  980.  
  981.   qtimer(Timeout);
  982.  
  983.   WaitSigs=(1L<<tport->mp_SigBit) | (1L<<NewPort->mp_SigBit);
  984.   if (TWindowOpen) WaitSigs|=(1L << XPRWin->UserPort->mp_SigBit);
  985.  
  986.   ReturnedSigs=Wait(WaitSigs);
  987.  
  988.   if (ReturnedSigs & (1L << XPRWin->UserPort->mp_SigBit))
  989.   {
  990. #ifdef debugmode
  991.     puts("window flag");
  992. #endif
  993.     if (xpr_chk4abort()==-1)
  994.     {
  995.       // abort everything, tidy up and return -1
  996.  
  997.       if (!CheckIO((struct IORequest *)xpr_serio))
  998.       {
  999.         AbortIO((struct IORequest *)xpr_serio);
  1000.       }
  1001.       WaitIO((struct IORequest *)xpr_serio);
  1002.  
  1003.       AbortIO((struct IORequest *)treq);
  1004.       WaitIO((struct IORequest *)treq);
  1005.  
  1006.       // cancel the transfer!
  1007.       xpr_swrite(ZModemCancel,20);
  1008.  
  1009.       #ifdef debugmode
  1010.       puts("xpr_sread, returning -1, aborted!");
  1011.       #endif
  1012.       return((LONG)-1);
  1013.     }
  1014.     // if we get here then it was not a cancel message that we received from
  1015.     // the window, so we can sit in the main loop abit more and wait for
  1016.     // another signal..
  1017.   }
  1018.  
  1019.   if (ReturnedSigs&(1L<<NewPort->mp_SigBit))
  1020.   {
  1021.     #ifdef debugmode
  1022.     puts("Serial Flag");
  1023.     #endif
  1024.     if (!CheckIO((struct IORequest *)xpr_serio))
  1025.     {
  1026.       AbortIO((struct IORequest *)xpr_serio);
  1027.     }
  1028.     WaitIO((struct IORequest *)xpr_serio);
  1029.  
  1030.     // and cleanup the timer and serial requests
  1031.     AbortIO((struct IORequest *)treq);
  1032.     WaitIO((struct IORequest *)treq);
  1033.  
  1034.     // and just in case any bytes were read by the serial port, return the amount
  1035.     // would be 0 if a timeout occured and no data was read
  1036.  
  1037.     #ifdef debugmode
  1038.     printf("xpr_sread, returning %ld\n",xpr_serio->IOSer.io_Actual);
  1039.     #endif
  1040.     return((LONG)xpr_serio->IOSer.io_Actual);
  1041.   }
  1042.  
  1043.   if (ReturnedSigs&(1L<<tport->mp_SigBit))
  1044.   {
  1045.     #ifdef debugmode
  1046.     puts("Timer Flag");
  1047.     #endif
  1048.     if (!CheckIO((struct IORequest *)xpr_serio))
  1049.     {
  1050.       AbortIO((struct IORequest *)xpr_serio);
  1051.     }
  1052.     WaitIO((struct IORequest *)xpr_serio);
  1053.  
  1054.     AbortIO((struct IORequest *)treq);
  1055.     WaitIO((struct IORequest *)treq);
  1056.  
  1057.     #ifdef debugmode
  1058.     printf("xpr_sread, returning %ld\n",xpr_serio->IOSer.io_Actual);
  1059.     #endif
  1060.     return((LONG)xpr_serio->IOSer.io_Actual);
  1061.   }
  1062.  
  1063.   // Should Never Get Here, if it does a false signal arrived!
  1064.   DOOR_SysopText("XPR Error - SR1\r\n");
  1065.   return(0);
  1066. }
  1067.  
  1068. LONG __saveds __asm xpr_sflush(void)
  1069. {
  1070. #ifdef debugmode
  1071.   printf("xpr_sflush\n");
  1072. #endif
  1073.  
  1074.   xpr_serio->IOSer.io_Command=CMD_FLUSH;
  1075.   DoIO((struct IORequest *)xpr_serio);
  1076.   return((LONG)xpr_serio->IOSer.io_Error);
  1077. }
  1078.  
  1079. #define ST_PARTYON  (1 << 0)
  1080. #define ST_PARTYODD (1 << 1)
  1081. #define ST_7WIRE  (1 << 2)
  1082. #define ST_QBREAK (1 << 3)
  1083. #define ST_RADBOOGIE  (1 << 4)
  1084. #define ST_SHARED (1 << 5)
  1085. #define ST_EOFMODE  (1 << 6)
  1086. #define ST_XDISABLED  (1 << 7)
  1087. #define ST_PARTYMARKON  (1 << 8)
  1088. #define ST_PARTYMARK  (1 << 9)
  1089. #define ST_2BITS  (1 << 10)
  1090. #define ST_READ7  (1 << 11)
  1091. #define ST_WRITE7 (1 << 12)
  1092.  
  1093. LONG __saveds __asm xpr_setserial(register __d0 LONG Status)
  1094. {
  1095.   STATIC LONG XprBauds[12] =
  1096.   {
  1097.     110,
  1098.     300,
  1099.     1200,
  1100.     2400,
  1101.     4800,
  1102.     9600,
  1103.     19200,
  1104.     31250,
  1105.     38400,
  1106.     57600,
  1107.     76800,
  1108.     115200
  1109.   };
  1110.  
  1111.   LONG Return,i;
  1112.  
  1113. #ifdef debugmode
  1114.   printf("xpr_setserial, status = %ld\n",Status);
  1115. #endif
  1116.  
  1117.   xpr_serio -> IOSer . io_Command = SDCMD_QUERY;
  1118.   DoIO((struct IORequest *)xpr_serio);
  1119.  
  1120.   Return = xpr_serio -> io_SerFlags & 0xFF;
  1121.  
  1122.   if(xpr_serio -> io_ExtFlags & SEXTF_MSPON)
  1123.     Return |= ST_PARTYMARKON;
  1124.  
  1125.   if(xpr_serio -> io_ExtFlags & SEXTF_MARK)
  1126.     Return |= ST_PARTYMARK;
  1127.  
  1128.   if(xpr_serio -> io_StopBits == 2)
  1129.     Return |= ST_2BITS;
  1130.  
  1131.   if(xpr_serio -> io_ReadLen == 7)
  1132.     Return |= ST_READ7;
  1133.  
  1134.   if(xpr_serio -> io_WriteLen == 7)
  1135.     Return |= ST_WRITE7;
  1136.  
  1137.   for(i = 0 ; i < 12 ; i++)
  1138.   {
  1139.     if(xpr_serio -> io_Baud == XprBauds[i])
  1140.     {
  1141.       Return |= (i << 16);   // uses 16MSB's of the LONGWORD for the speed ?
  1142.  
  1143.       break;
  1144.     }
  1145.   }
  1146.  
  1147.   if(Status != -1)
  1148.   {
  1149.     xpr_serio -> IOSer . io_Command = SDCMD_SETPARAMS;
  1150.  
  1151.     xpr_serio -> io_SerFlags    = Status & 0xFF;
  1152.     xpr_serio -> io_ExtFlags    = 0;
  1153.  
  1154.     if(Status & ST_PARTYMARKON)
  1155.       xpr_serio -> io_ExtFlags |= SEXTF_MSPON;
  1156.  
  1157.     if(Status & ST_PARTYMARK)
  1158.       xpr_serio -> io_ExtFlags |= SEXTF_MARK;
  1159.  
  1160.     if(Status & ST_2BITS)
  1161.       xpr_serio -> io_StopBits = 2;
  1162.     else
  1163.       xpr_serio -> io_StopBits = 1;
  1164.  
  1165.     if(Status & ST_READ7)
  1166.       xpr_serio -> io_ReadLen = 7;
  1167.     else
  1168.       xpr_serio -> io_ReadLen = 8;
  1169.  
  1170.     if(Status & ST_WRITE7)
  1171.       xpr_serio -> io_WriteLen = 7;
  1172.     else
  1173.       xpr_serio -> io_WriteLen = 8;
  1174.  
  1175.     DoIO((struct IORequest *)xpr_serio);
  1176.  
  1177.   }
  1178.  
  1179.   return(Return);
  1180.  
  1181. }
  1182. /* EOT [end of theft] */
  1183.  
  1184. void OpenTransferWindow( void )
  1185. {
  1186.   struct Screen *Scr=NULL;
  1187.  
  1188.   if (!TWindowOpen)
  1189.   {
  1190.     if (HBBSFont=OpenDiskFont( &HBBS8066 ) )
  1191.     {
  1192.       if (N_ND->ConOK && N_ND->NodeSettings.UseOwnScreen)
  1193.       {
  1194.         sprintf(outstr,"NodeWatch_%d",N_ND->NodeNum);
  1195.         Scr = LockPubScreen(outstr);
  1196.       }
  1197.       if (!Scr)
  1198.       {
  1199.         Scr = LockPubScreen( "CtrlScrn" );
  1200.       }
  1201.       if (Scr)
  1202.       {
  1203.         if (OpenWindowXPRWin(Scr)==0)
  1204.         {
  1205.           // Opened OK
  1206.           TWindowOpen=TRUE;
  1207.         }
  1208.         UnlockPubScreen( NULL, Scr);
  1209.       }
  1210.     }
  1211.   }
  1212. }
  1213.  
  1214. void CloseTransferWindow( void )
  1215. {
  1216.   if (HBBSFont) CloseFont(HBBSFont);
  1217.   if (TWindowOpen)
  1218.   {
  1219.     CloseWindowXPRWin();
  1220.     TWindowOpen=FALSE;
  1221.   }
  1222. }
  1223.  
  1224. void KeepFlushing( void )
  1225. {
  1226.   BOOL Done=FALSE;
  1227.  
  1228.   do
  1229.   {
  1230.     switch(DOOR_GetLine(GL_IMMEDIATE,'\0',1,2,NULL))
  1231.     {
  1232.       case IN_LOSSCARRIER:
  1233.       case IN_TIMEOUT:
  1234.         Done=TRUE;
  1235.         break;
  1236.     }
  1237.   } while (!Done);
  1238. }
  1239.  
  1240. void Xfer( void )
  1241. {
  1242.   if (XProtocolBase=OpenLibrary(xprlibname,0))
  1243.   {
  1244.     if (xio=(struct XPR_IO*)AllocVec(sizeof (struct XPR_IO),MEMF_CLEAR))
  1245.     {
  1246.       xio->xpr_fopen     = xpr_fopen;
  1247.       xio->xpr_fclose    = xpr_fclose;
  1248.       xio->xpr_fread     = xpr_fread;
  1249.       xio->xpr_fwrite    = xpr_fwrite;
  1250.  
  1251.       xio->xpr_swrite    = xpr_swrite;
  1252.       xio->xpr_sread     = xpr_sread;
  1253.       xio->xpr_sflush    = xpr_sflush;
  1254.       xio->xpr_setserial = xpr_setserial;
  1255.  
  1256.       xio->xpr_update    = xpr_displayupdate;
  1257.       xio->xpr_chkabort  = xpr_chk4abort;
  1258.       xio->xpr_ffirst    = xpr_ffirst;
  1259.       xio->xpr_fnext     = xpr_fnext;
  1260.       xio->xpr_finfo     = xpr_finfo;
  1261.       xio->xpr_fseek     = xpr_fseek;
  1262.       xio->xpr_gets      = xpr_gets;
  1263.       xio->xpr_unlink    = xpr_unlink;
  1264.  
  1265.       AbortSerRead();
  1266.  
  1267.       if (GrabSerial())
  1268.       {
  1269.         // from this point on DON'T USE DOOR_WriteText(), use DOOR_SysopText() instead!
  1270.         // or you will corrupt the transfer!
  1271.  
  1272.         if (opentimer()==0)
  1273.         {
  1274.  
  1275.           xio->xpr_filename=xprlibopts;
  1276.  
  1277.  
  1278. //          DOOR_SysopText("protocol options= \"");
  1279. //          if (xprlibopts) DOOR_SysopText(xprlibopts);
  1280. //          DOOR_SysopText("\"\r\n");
  1281.  
  1282.           OpenTransferWindow();
  1283.  
  1284.           if(XProtocolSetup(xio))
  1285.           {
  1286.  
  1287.             if (UL_Files) // Uploading ??
  1288.             {
  1289.               // init filename with finename of first the first..
  1290.  
  1291.               xio->xpr_filename=HBBS_ListName(UL_FileList,0);
  1292.               TransferType=T_SEND;
  1293.               XProtocolSend(xio);
  1294.             }
  1295.             else // nope, Downloading ?
  1296.             {
  1297.               if (DL_PathOK)
  1298.               {
  1299.                 // Yup...
  1300.  
  1301.                 // init filename with path to download files..
  1302.  
  1303.                 xio->xpr_filename=DL_Path;
  1304.  
  1305.                 TransferType=T_RECEIVE;
  1306.                 XProtocolReceive(xio);
  1307.               }
  1308.             }
  1309.             XProtocolCleanup(xio);
  1310.           }
  1311.  
  1312.           CloseTransferWindow();
  1313.  
  1314.           closetimer();
  1315.         }
  1316.         else
  1317.         {
  1318.           DOOR_SysopText("Failed To Open Timer!\r\n");
  1319.         }
  1320.         ReleaseSerial();
  1321.  
  1322.         KeepFlushing();
  1323.  
  1324.       }
  1325.       else
  1326.       {
  1327.         DOOR_WriteText("Failed To Open Serial!\r\n");
  1328.       }
  1329.       FreeVec(xio);
  1330.     }
  1331.     CloseLibrary(XProtocolBase);
  1332.   }
  1333.   else
  1334.   {
  1335.     DOOR_WriteText("Failed to open \"");
  1336.     DOOR_WriteText(xprlibname);
  1337.     DOOR_WriteText("\" Exiting!\r\n");
  1338.   }
  1339.  
  1340. }
  1341.  
  1342. void CheckULList(void)
  1343. {
  1344.   struct FileBuffer *node;
  1345.   struct TaggedFile *Tag;
  1346.  
  1347.   for (node = (struct FileBuffer *)UL_FileList->lh_Head ; node->node.ln_Succ ; node =(struct FileBuffer *)node->node.ln_Succ)
  1348.   {
  1349.     if (node->ActualSize==node->BytesTransferred)
  1350.     {
  1351.       N_ND->Actions[ACTN_DOWNLOAD]=ACTC_DOWNLOAD;
  1352.  
  1353.       // transferred the file ok, remove creds (if applicable)
  1354.       // and write to callers log and ul/dl log..
  1355.  
  1356.       sprintf(outstr,"DOWNLOADED File:\"%s\" Size:%ld",node->node.ln_Name,node->ActualSize);
  1357.       HBBS_AddToCallersLog(outstr);
  1358.  
  1359.       N_ND->User.CallData.ActualDownloadFiles++;
  1360.       N_ND->User.NormalData.ActualDownloadFiles++;
  1361.       N_ND->User.CallData.ActualDownloadBytes+=node->ActualSize;
  1362.       N_ND->User.NormalData.ActualDownloadBytes+=node->ActualSize;
  1363.  
  1364.       N_ND->User.FilesDownloaded++;
  1365.       N_ND->User.BytesDownloaded+=node->ActualSize;
  1366.  
  1367.       if (Tag=HBBS_FindTag(node->node.ln_Name,TRUE))
  1368.       {
  1369.         if (TakeCreds && Tag->WarezFile && node->BlocksTransferred && N_ND->User.Valid && node->ReadFile)
  1370.         {
  1371.           sprintf(outstr,ANSI_RESET ANSI_FG_CYAN "Removing "ANSI_FG_WHITE"%6ld"ANSI_FG_CYAN" credits for file: "ANSI_FG_WHITE"%s\r\n",node->ActualSize,FilePart(node->node.ln_Name));
  1372.           DOOR_WriteText(outstr);
  1373.  
  1374.           N_ND->User.CallData.DownloadFiles++;
  1375.           N_ND->User.NormalData.DownloadFiles++;
  1376.  
  1377.           N_ND->User.CallData.DownloadBytes+=Tag->FileSize;
  1378.           N_ND->User.NormalData.DownloadBytes+=Tag->FileSize;
  1379.         }
  1380.  
  1381.         // and remove the tagged file
  1382.  
  1383.         N_ND->TaggedFiles--; // first! :-)
  1384.         Remove((struct Node*)Tag);
  1385.  
  1386.         FreeStr(Tag->node.ln_Name);
  1387.         FreeVec(Tag);
  1388.       }
  1389.  
  1390.  
  1391.     }
  1392.     else
  1393.     {
  1394.       // *C* add U/D log too..
  1395.       // failed transferring that file, leave it tagged and write to the log..
  1396.       sprintf(outstr,"FAILED DOWNLOAD File:\"%s\" Size:%ld Transferred:%ld",node->node.ln_Name,node->ActualSize,node->BytesTransferred);
  1397.       HBBS_AddToCallersLog(outstr);
  1398.       N_ND->Actions[ACTN_FAILEDDOWNLOAD]=ACTC_FAILEDDOWNLOAD;
  1399.  
  1400.     }
  1401.   }
  1402. }
  1403.  
  1404. void CheckDLList(void)
  1405. {
  1406.   struct FileBuffer *node;
  1407.  
  1408.   for (node = (struct FileBuffer *)DL_FileList->lh_Head ; node->node.ln_Succ ; node =(struct FileBuffer *)node->node.ln_Succ)
  1409.   {
  1410.     if (node->ActualSize==node->BytesTransferred)
  1411.     {
  1412.       // transferred the file ok, add creds (if applicable)
  1413.       // and write to callers log and ul/dl log..
  1414.  
  1415.       N_ND->User.CallData.ActualUploadFiles++;
  1416.       N_ND->User.NormalData.ActualUploadFiles++;
  1417.       N_ND->User.CallData.ActualUploadBytes+=node->ActualSize;
  1418.       N_ND->User.NormalData.ActualUploadBytes+=node->ActualSize;
  1419.  
  1420.       N_ND->User.FilesUploaded++;
  1421.       N_ND->User.BytesUploaded+=node->ActualSize;
  1422.  
  1423.       sprintf(outstr,"UPLOADED File:\"%s\" Size:%ld",node->node.ln_Name,node->ActualSize);
  1424.       HBBS_AddToCallersLog(outstr);
  1425.       N_ND->Actions[ACTN_UPLOAD]=ACTC_UPLOAD;
  1426.  
  1427.  
  1428.     }
  1429.     else
  1430.     {
  1431.       // *C* add U/D log too..
  1432.       // failed transferring that file, leave it tagged and write to the log..
  1433.  
  1434.       N_ND->Actions[ACTN_FAILEDUPLOAD]=ACTC_FAILEDUPLOAD;
  1435.  
  1436.       sprintf(outstr,"FAILED UPLOAD File:\"%s\" Size:%ld Transferred:%ld",node->node.ln_Name,node->ActualSize,node->BytesTransferred);
  1437.       HBBS_AddToCallersLog(outstr);
  1438.  
  1439.  
  1440.       sprintf(outstr,ANSI_RESET ANSI_FG_CYAN "Moving failed file"ANSI_FG_BLUE": "ANSI_FG_WHITE"%s"ANSI_FG_CYAN" Size"ANSI_FG_BLUE": "ANSI_FG_WHITE"%ld\r\n",node->node.ln_Name,node->BytesTransferred);
  1441.       DOOR_WriteText(outstr);
  1442.  
  1443.       sprintf(outstr,"%s@%ld",node->node.ln_Name,N_ND->User.CallData.UserID);
  1444.  
  1445.       if (Rename(node->node.ln_Name,outstr))
  1446.       {
  1447.         sprintf(outstr,"%sPARTUPLOAD %s@%ld",N_ND->OnlineStatus==OS_ONLINE ? "" : "NOUSER ",FilePart(node->node.ln_Name),N_ND->User.CallData.UserID); // move NOUSER to the door's system options!!!
  1448.         DOOR_SystemDoor("MoveFile",outstr);
  1449.       }
  1450.       else
  1451.       {
  1452.         DeleteFile(node->node.ln_Name);
  1453.       }
  1454.  
  1455.     }
  1456.   }
  1457. }
  1458.  
  1459. void DoorMain(int argc,char *argv[])
  1460. {
  1461.   long loop;
  1462.  
  1463.   BOOL AddTags=0;
  1464.   BOOL SystemFiles=TRUE;
  1465.   BOOL WarezFiles=TRUE;
  1466.  
  1467.   struct TaggedFile *Tag;
  1468.   struct FileBuffer *NewFileNode;
  1469.   char tmpname[1024];
  1470.  
  1471.   BPTR FL;
  1472.   struct FileInfoBlock FB;
  1473.  
  1474.  
  1475.   if (UL_FileList=HBBS_CreateList())
  1476.   {
  1477.     if (DL_FileList=HBBS_CreateList())
  1478.     {
  1479.       xprlibname=argv[2];
  1480.  
  1481.       // add list of tagged files to our list of files to transfer..
  1482.  
  1483.  
  1484.       // then check the parameters to see if we have any other options..
  1485.       // remembering to miss out the arguments that we've already checked
  1486.       // (hence starting the loop from startparam)
  1487.  
  1488.       for(loop=3;loop<argc;loop++) // if there are any parameters then display them
  1489.       {
  1490.         switch(toupper(argv[loop][0]))
  1491.         {
  1492.           case 'S' :
  1493.             CheckConfPaths=TRUE;
  1494.             break;
  1495.  
  1496.           case 'C' :
  1497.             TakeCreds=TRUE;
  1498.             break;
  1499.  
  1500.           case 'U' :
  1501.             strcpy(tmpname,&argv[loop][2]);
  1502.             if (!(FL=Lock(tmpname,SHARED_LOCK))) // does the file exist ?
  1503.             {
  1504.               if (UL_PathOK)
  1505.               {
  1506.                 strcpy(tmpname,UL_Path);
  1507.                 strcat(tmpname,&argv[loop][2]); // same as argv[loop]+2, start at 3rd char..
  1508.                 FL=Lock(tmpname,SHARED_LOCK);
  1509.               }
  1510.             }
  1511.             if (FL)
  1512.             {
  1513.               if (Examine(FL,&FB))
  1514.               {
  1515.                 if (NewFileNode=(struct FileBuffer*)HBBS_CreateNode(tmpname,sizeof(struct FileBuffer)))
  1516.                 {
  1517.                    // all othe rparams are set to null by HBBS_CreateNode()
  1518.                   NewFileNode->ActualSize=FB.fib_Size;
  1519.                   AddTail(UL_FileList,(struct Node *)NewFileNode);
  1520.                   UL_Files++;
  1521.                 }
  1522.  
  1523.               }
  1524.               UnLock(FL);
  1525.             }
  1526.  
  1527.             break;
  1528.  
  1529.           case 'O' :
  1530.             xprlibopts=&argv[loop][2];
  1531.             break;
  1532.  
  1533.           case 'D' :
  1534.             if (!DL_PathOK) // only allowed ONE download path!
  1535.             {
  1536.               DL_Path=&argv[loop][2];
  1537.               if (PathOK(DL_Path)) DL_PathOK=TRUE;
  1538.             }
  1539.             break;
  1540.  
  1541.           case 'W' :
  1542.             if (!UL_PathOK) // only allowed ONE download path!
  1543.             {
  1544.               UL_Path=&argv[loop][2];
  1545.               if (PathOK(UL_Path)) UL_PathOK=TRUE;
  1546.             }
  1547.             break;
  1548.  
  1549.           default:
  1550.             if (stricmp(argv[loop],"TAGS")==0)
  1551.             {
  1552.               AddTags=TRUE;
  1553.             }
  1554.  
  1555.             if (stricmp(argv[loop],"NOSYSTEM")==0)
  1556.             {
  1557.               SystemFiles=FALSE;
  1558.             }
  1559.  
  1560.             if (stricmp(argv[loop],"NOWAREZ")==0)
  1561.             {
  1562.               WarezFiles=FALSE;
  1563.             }
  1564.  
  1565.             break;
  1566.  
  1567.         }
  1568.       }
  1569.  
  1570.       if (AddTags)
  1571.       {
  1572.         if (N_ND->TaggedFiles)
  1573.         {
  1574.           for (Tag=(struct TaggedFile *)N_ND->TaggedFileList->lh_Head;Tag->node.ln_Succ;Tag=(struct TaggedFile *)Tag->node.ln_Succ)
  1575.           {
  1576.             if (((Tag->WarezFile==TRUE) && (WarezFiles)) || ((Tag->WarezFile==FALSE) && (SystemFiles)))
  1577.             {
  1578.               if (NewFileNode=(struct FileBuffer*)HBBS_CreateNode(Tag->node.ln_Name,sizeof(struct FileBuffer)))
  1579.               {
  1580.                 NewFileNode->ActualSize=Tag->FileSize;
  1581.                 AddTail(UL_FileList,(struct Node*)NewFileNode);
  1582.                 UL_Files++;
  1583.               }
  1584.             }
  1585.           }
  1586.         }
  1587.       }
  1588.  
  1589.       if ((xprlibname) && ((UL_Files || DL_PathOK)) )
  1590.       {
  1591.         Xfer();
  1592.       }
  1593.       DOOR_WriteText("\r\n");
  1594.  
  1595.       CheckDLList();
  1596.       FreeStrList(DL_FileList); // then free it!
  1597.     }
  1598.     CheckULList();
  1599.     FreeStrList(UL_FileList);
  1600.  
  1601.  
  1602.     HBBS_SaveUserData(&N_ND->User.NormalData);
  1603.     // just in case the user decided to loose carrier! :-)
  1604.     // or if the bbs crashed (heaven forbid..) before the data was saved normally.
  1605.   }
  1606. }
  1607.  
  1608. int main(int argc,char *argv[])
  1609. {
  1610.   if (sscanf(argv[1],"%d",&N_NodeNum)==0)
  1611.   {
  1612.     printf("Invalid/No Paramaters for door!\n");
  1613.     exit (20);
  1614.   }
  1615.   init("XPR");
  1616.  
  1617.   SetTaskPri(FindTask(0),2); // *C* make configurable!!!
  1618.  
  1619.   if (BBSGlobal=HBBS_GimmeBBS())
  1620.   {
  1621.     if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
  1622.     {
  1623.       DoorMain(argc,argv);
  1624.     }
  1625.   }
  1626.   cleanup(0);
  1627. }
  1628.